class ConObjectiveVolume extends PhysicsVolume
	placeable;

var(ConProperties) byte             ConAssociatedStage;
var(ConProperties) ConObjective     ConAssociatedPoint;
var(ConProperties) bool             bStartInteractive;
var(ConProperties) float            ActionPerSec;
var                bool             bInteractive;
var                info             InteractTimer;

simulated event PostBeginPlay()
{
	Super.PostBeginPlay();

	bInteractive = bStartInteractive;

	if ( Role < ROLE_Authority )
		return;
	if ( bInteractive )
		InteractTimer = Spawn(class'VolumeTimer', self);
}          

/*
TimerPop
damage touched actors if pain causing.
since PhysicsVolume is static, this function is actually called by a volumetimer
*/
function TimerPop(VolumeTimer T)
{
	local actor A;

	if ( T == InteractTimer )
	{
		if ( !bInteractive )
			return;

		ForEach TouchingActors(class'Actor', A)
			if ( UTPawn(A) != None)
			{
				CauseInteraction(A);
			}
	}
}

simulated event Touch( Actor Other, PrimitiveComponent OtherComp, vector HitLocation, vector HitNormal )
{
	if ( (Other == None) || Other.bStatic || UTPawn(Other) == None) //UTPawn check ensures things like rockets will not interact
		return;
	
	CauseInteraction(Other);
}

function CauseInteraction(Actor Other)
{
	if ( (Other == None) || Other.bStatic || UTPawn(Other) == None) //UTPawn check ensures things like rockets will not interact
		return;

	if ( UTPawn(Other).PlayerReplicationInfo.Team.TeamIndex == ConAssociatedPoint.ConOwnerTeam)
	{
		if (ConAssociatedPoint.Health < ConAssociatedPoint.BaseHealth)
		{
			ConAssociatedPoint.Health = ConAssoCiatedPoint.Health + ActionPerSec;
			ConAssociatedPoint.CheckHealth();
		}
		
	} else {
		ConAssociatedPoint.Health = ConAssoCiatedPoint.Health - ActionPerSec;
		ConAssociatedPoint.CheckHealth();
	}
}

DefaultProperties
{
	Begin Object Name=BrushComponent0
		CollideActors=true
		BlockActors=false
		BlockZeroExtent=true
		BlockNonZeroExtent=true
		BlockRigidBody=false
	End Object
	
    RemoteRole=ROLE_SimulatedProxy
    NetUpdateFrequency=0.1
    bSkipActorPropertyReplication=true
  	bAlwaysRelevant=true
	name="ConObjectiveVolume"
	
	bStartInteractive=true
	ConAssociatedStage=1
	ActionPerSec=50
}
